﻿using System;
using System.Data.SqlServerCe;

using palmApp.Database;

namespace palmApp.Session
{
    public sealed class mobileSession
    {
        private Manager dbManager;
        private SqlCeDataReader dr;

        // Session attributes from responsible table
        public Int32 comtec_id_responsible;
        public String tag_id_responsible;
        public String cod_mainteiner;
        public String name;
        public String lastname1;
        public String lastname2;
        public String rut;
        public String charge;
        public DateTime income_date;
        public DateTime birthdate;
        public String notes;

        public void Clear()
        {
            this.comtec_id_responsible = 0;
            this.tag_id_responsible = "";
            this.cod_mainteiner = "";
            this.name = "";
            this.lastname1 = "";
            this.lastname2 = "";
            this.rut = "";
            this.charge = "";
            this.notes = "";
        }

        public void Read()
        {
            dbManager = new Manager();
            dbManager.Query("SELECT * FROM responsible WHERE tag_id_responsible = '" + tag_id_responsible + "'");
            dr = dbManager.Command.ExecuteReader();

            if (true)
            {
                while (dr.Read())
                {
                    comtec_id_responsible   = Convert.ToInt32(dr["comtec_id_responsible"].ToString());
                    cod_mainteiner          = dr["cod_mainteiner"].ToString();
                    name                    = dr["name"].ToString();
                    lastname1               = dr["lastname1"].ToString();
                    lastname2               = dr["lastname2"].ToString();
                    rut                     = dr["rut"].ToString();
                    charge                  = dr["charge"].ToString();
                    income_date             = Convert.ToDateTime(dr["income_date"].ToString());
                    birthdate               = Convert.ToDateTime(dr["birthdate"].ToString());
                    notes                   = dr["notes"].ToString();
                }
            }

            dr.Close();
            dr.Dispose();
            dbManager.Close();
            dbManager = null;
        }

        // singleton class

        static readonly mobileSession instance = new mobileSession();

        static mobileSession()
        {
        }

        mobileSession()
        {
        }

        public static mobileSession Instance
        {
            get
            {
                return instance;
            }
        }
    }
}
